(function (F) {
    F.fn.paginate = function (H) {
        var G = F.extend({}, F.fn.paginate.defaults, H);
        return this.each(function () {
            $this = F(this);
            var I = F.meta ? F.extend({}, G, $this.data()) : G;
            var J = I.start;
            F.fn.draw(I, $this, J)
        })
    };
    var B = 0;
    var C = 0;
    var D = navigator.appName;
    var E = navigator.appVersion;
    if (E.indexOf("MSIE 7.0") > 0) {
        var A = "ie7"
    }
    F.fn.paginate.defaults = {
        count: 5,
        start: 12,
        display: 5,
        border: true,
        border_color: "#fff",
        text_color: "#8cc59d",
        background_color: "black",
        border_hover_color: "#fff",
        text_hover_color: "#fff",
        background_hover_color: "#fff",
        rotate: true,
        images: true,
        mouse: "slide",
        onChange: function () {
            return false
        }
    };
    F.fn.draw = function (S, M, b) {
        if (S.display > S.count) {
            S.display = S.count
        }
        $this.empty();
        if (S.images) {
            var P = "jPag-sprevious-img";
            var L = "jPag-previous-img";
            var f = "jPag-snext-img";
            var T = "jPag-next-img"
        } else {
            var P = "jPag-sprevious";
            var L = "jPag-previous";
            var f = "jPag-snext";
            var T = "jPag-next"
        }
        var Z = F(document.createElement("a")).addClass("jPag-first").html("首页");
        if (S.rotate) {
            if (S.images) {
                var G = F(document.createElement("span")).addClass(P)
            } else {
                var G = F(document.createElement("span")).addClass(P).html("&lt;")
            }
        }
        var H = F(document.createElement("div")).addClass("jPag-control-back");
        H.append(Z).append(G);
        var I = F(document.createElement("div")).css("overflow", "hidden");
        var g = F(document.createElement("ul")).addClass("jPag-pages");
        var O = (S.display - 1) / 2;
        var R = b - O;
        var Y;
        for (var K = 0; K < S.count; K++) {
            var N = K + 1;
            if (N == b) {
                var W = F(document.createElement("li")).html('<span class="jPag-current">' + N + "</span>");
                Y = W;
                g.append(W)
            } else {
                var W = F(document.createElement("li")).html("<a>" + N + "</a>");
                g.append(W)
            }
        }
        I.append(g);
        if (S.rotate) {
            if (S.images) {
                var e = F(document.createElement("span")).addClass(f)
            } else {
                var e = F(document.createElement("span")).addClass(f).html("&gt;")
            }
        }
        var Q = F(document.createElement("a")).addClass("jPag-last").html("末页");
        var h = F(document.createElement("div")).addClass("jPag-control-front");
        h.append(e).append(Q);
        if (S.maxRows != null) {
            var maxRows = F(document.createElement("a")).addClass("jPag-last").html("共" + S.maxRows);
            h.append(maxRows);
        }
        $this.addClass("jPaginate").append(H).append(I).append(h);
        if (!S.border) {
            if (S.background_color == "none") {
                var a = {
                    "color": S.text_color
                }
            } else {
                var a = {
                    "color": S.text_color,
                    "background-color": S.background_color
                }
            }
            if (S.background_hover_color == "none") {
                var X = {
                    "color": S.text_hover_color
                }
            } else {
                var X = {
                    "color": S.text_hover_color,
                    "background-color": S.background_hover_color
                }
            }
        } else {
            if (S.background_color == "none") {
                var a = {
                    "color": S.text_color,
                    "border": "1px solid " + S.border_color
                }
            } else {
                var a = {
                    "color": S.text_color,
                    "background-color": S.background_color,
                    "border": "1px solid " + S.border_color
                }
            }
            if (S.background_hover_color == "none") {
                var X = {
                    "color": S.text_hover_color,
                    "border": "1px solid " + S.border_hover_color
                }
            } else {
                var X = {
                    "color": S.text_hover_color,
                    "background-color": S.background_hover_color,
                    "border": "1px solid " + S.border_hover_color
                }
            }
        }
        F.fn.applystyle(S, $this, a, X, Z, g, I, h);
        var U = B - Z.parent().width() - 3;
        if (A == "ie7") {
            I.css("width", U + 72 + "px");
            h.css("left", B + 6 + 72 + "px")
        } else {
            I.css("width", U + "px");
            h.css("left", B + 6 + "px")
        }
        if (S.rotate) {
            e.hover(function () {
                thumbs_scroll_interval = setInterval(function () {
                    var c = I.scrollLeft() + 1;
                    I.scrollLeft(c)
                }, 20)
            }, function () {
                clearInterval(thumbs_scroll_interval)
            });
            G.hover(function () {
                thumbs_scroll_interval = setInterval(function () {
                    var c = I.scrollLeft() - 1;
                    I.scrollLeft(c)
                }, 20)
            }, function () {
                clearInterval(thumbs_scroll_interval)
            });
            if (S.mouse == "press") {
                e.mousedown(function () {
                    thumbs_mouse_interval = setInterval(function () {
                        var c = I.scrollLeft() + 5;
                        I.scrollLeft(c)
                    }, 20)
                }).mouseup(function () {
                    clearInterval(thumbs_mouse_interval)
                });
                G.mousedown(function () {
                    thumbs_mouse_interval = setInterval(function () {
                        var c = I.scrollLeft() - 5;
                        I.scrollLeft(c)
                    }, 20)
                }).mouseup(function () {
                    clearInterval(thumbs_mouse_interval)
                })
            } else {
                G.click(function (c) {
                    var j = U - 10;
                    var i = I.scrollLeft() - j;
                    I.animate({
                        scrollLeft: i + "px"
                    })
                });
                e.click(function (c) {
                    var j = U - 10;
                    var i = I.scrollLeft() + j;
                    I.animate({
                        scrollLeft: i + "px"
                    })
                })
            }
        }
        Z.click(function (c) {
            I.animate({
                scrollLeft: "0px"
            });
            I.find("li").eq(0).click()
        });
        Q.click(function (c) {
            I.animate({
                scrollLeft: C + "px"
            });
            I.find("li").eq(S.count - 1).click()
        });
        I.find("li").click(function (i) {
            Y.html("<a>" + Y.find(".jPag-current").html() + "</a>");
            var l = F(this).find("a").html();
            F(this).html('<span class="jPag-current">' + l + "</span>");
            Y = F(this);
            F.fn.applystyle(S, F(this).parent().parent().parent(), a, X, Z, g, I, h);
            var j = (this.offsetLeft) / 2;
            var k = I.scrollLeft() + j;
            var c = j - (U / 2);
            if (A == "ie7") {
                I.animate({
                    scrollLeft: j + c - Z.parent().width() + 52 + "px"
                })
            } else {
                I.animate({
                    scrollLeft: j + c - Z.parent().width() + "px"
                })
            }
            S.onChange(l)
        });
        var V = I.find("li").eq(S.start - 1);
        V.attr("id", "tmp");
        var d = document.getElementById("tmp").offsetLeft / 2;
        V.removeAttr("id");
        var J = d - (U / 2);
        if (A == "ie7") {
            I.animate({
                scrollLeft: d + J - Z.parent().width() + 52 + "px"
            })
        } else {
            I.animate({
                scrollLeft: d + J - Z.parent().width() + "px"
            })
        }
    };
    F.fn.applystyle = function (L, N, H, I, M, G, K, J) {
        N.find("a").css(H);
        N.find("span.jPag-current").css(I);
        N.find("a").hover(function () {
            F(this).css(I)
        }, function () {
            F(this).css(H)
        });
        N.css("padding-left", M.parent().width() + 5 + "px");
        C = 0;
        N.find("li").each(function (O, P) {
            if (O == (L.display - 1)) {
                B = this.offsetLeft + this.offsetWidth
            }
            C += this.offsetWidth
        });
        C += 5;
        G.css("width", C + "px")
    }
})(jQuery);